using System;
using System.Collections.Generic;
using System.Text;
using IronMis2.Models;
using NUnit.Framework;

namespace IronMis2.Tests.Models
{
    [TestFixture]
    public class DepartmentTestCase : AbstractModelTestCase
    {
        [Test]
        public void CanCreateDepartment()
        {
            Company comp = Company.FindFirst();

            Department dep = new Department();
            dep.Name = "depart 1";
            dep.Company = comp;

            dep.Save();
            
            Flush();

            Department dbdep = Department.Find(dep.Id);
            Assert.AreEqual(dep.Name,dbdep.Name);
            Assert.IsNotNull(dep.Company);
        }

        [Test]
        public void WillNotDeleteAllItsEmployees()
        {
            Company comp = Company.FindFirst();
            if (comp == null)
            {
                comp = new Company();
                comp.Save();
            }
            Department dep = new Department();
            dep.Name = "depart 1";
            dep.Company = comp;
            dep.Save();

            Employee employee = new Employee();
            employee.UserId = Guid.NewGuid().ToString();
            employee.Password = "password";
            employee.Save();
            employee.Department = dep;

            dep.Delete();

            Flush();

            Employee dbemployee = Employee.Find(employee.Id);
            Assert.IsNotNull(dbemployee);
        }
    }
}
